#include <iostream>
#include <vector>
using namespace std;

const int N=1e4+10;

vector<pair<int,int>> edge[N];
int ret;
int dfs(int u,int father)
{
	int dist=0;
	int d1=0,d2=0;
	for(auto& t:edge[u])
	{
		if(t.first==father)
			continue;
		
		int d=dfs(t.first,u)+t.second;
		dist=max(d,dist);
		if(d>=d1) 
			d2=d1,d1=d;
		else if(d>d2)
			d2=d;
	}
	ret=max(ret,d1+d2);
	return dist;
}

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		edge[a].push_back({b,c});
		edge[b].push_back({a,c});
		
	}
	dfs(1,-1);
	cout<<ret<<endl;
	return 0;
}
